$(function() {
    toastr.options = {
        "newestOnTop": false,
        "timeOut": 1500,
        "extendedTimeOut": 0,
        "escapeHtml": true,
        "positionClass": "toast-bottom-center"
    };
    $('#hotel-panel-carousel').carousel({
        interval: 2000
    });
    $('#hotel-panel-carousel').on('slid.bs.carousel', function() {
        $('html,body').trigger('scroll');
    });

    $('#hotel-panel').on('click', '.hotel-more-info-trigger', function(e) {
        e.preventDefault();
        var trigger = $(this);
        if (trigger.hasClass('revert')) {
            $('#hotel-panel .hotel-more-info').addClass('hidden');
        } else {
            $('#hotel-panel .hotel-more-info').removeClass('hidden');
        }
        trigger.toggleClass('revert');
    });
    var getParams = getArgs();
    window.currentHotel = getParams.hotel;
    window.transCurrencyId = '';
    if (window.currentHotel === undefined || window.currentHotel === '') {
        toastr.error(lang('toastr.grogshop'));
    } else {
        //优惠券
        $('#enter-hotel-coupon').removeClass('hidden');
        ajaxRequest('/Home/Public/getHotelTipCoupon', {
            "hotel": window.currentHotel
        }, 'post', function (data) {
            var info = data.data;
            if(info.length !== 0){
                var robModal = $('#robModal');
                window.couponNo = info.couponNo;
                window.couponType = info.couponType;
                window.couponMinusPrice = info.couponMinusPrice;
                window.couponDiscount = info.couponDiscount;            
                if(info.couponType == 1){
                    robModal.find('.coupon-price').removeClass('hidden').find('span').text(info.couponMinusPrice);
                }else{
                    robModal.find('.coupon-discount').removeClass('hidden').find('span').text(info.couponDiscount);
                }               
                robModal.removeClass('hidden');                
            }
        }, function(error){
            toastr.error(typeof error.responseJSON === 'undefined' ? lang('tip.server') : error.responseJSON.info);
        });       
        
        toggleLoading(true);
        ajaxRequest('/Home/Hotel/info', {
            'hotel': window.currentHotel
        }, 'post', function(data) {
            toggleLoading(false);
            var hotelInfo = data.data;
            if(hotelInfo.defaultCurrency.symbol){
                window.symbols = hotelInfo.defaultCurrency.symbol;
                $('.multiCurrencySelect').find('[data-toggle="dropdown"]').find('.info').html(hotelInfo.defaultCurrency.name);
            }else{
                window.symbols = '￥';
            }
            window.isSplitOrderTime = hotelInfo.isSplitOrderTime;
            $('#hotel-panel .main-pic').css("background-image","url("+hotelInfo.logoImageUrl+")");
            if (hotelInfo.hotelIcon.hotelIcon == true  || hotelInfo.hotelIcon.hotelSafeguardIcon == true  || hotelInfo.hotelIcon.hotelCreditIcon == true  || hotelInfo.hotelIcon.hotelBrandIcon == true) {
                $('#hotel-icon-content').removeClass('hidden');
            }
            if (hotelInfo.hotelIcon.hotelIcon == true) {
                $('#hotelvicon').removeClass('hidden');
            }
            if (hotelInfo.hotelIcon.hotelSafeguardIcon == true) {
                $('#hotelsafeicon').removeClass('hidden');
            }
            if (hotelInfo.hotelIcon.hotelCreditIcon == true) {
                $('#hotelcrediticon').removeClass('hidden');
            }
            if (hotelInfo.hotelIcon.hotelBrandIcon == true) {
                $('#hotelbrandicon').removeClass('hidden');
            }

            $(document).attr('title', hotelInfo.hotelName);
            $('#doc-header .navbar-title').html(hotelInfo.hotelName);
            $('#hotel-cover .inner-item').attr('data-original', hotelInfo.coverImageUrl).lazyload();
            $('#hotel-panel-carousel .carousel-caption').html(hotelInfo.hotelName);
            var hotelPanel = $('#hotel-panel');
            hotelPanel.find('.hotel-panel-contact').html(hotelInfo.contact);
            hotelPanel.find('.hotel-panel-mobile').html('+'+ hotelInfo.areaCode+'&nbsp;'+hotelInfo.mobile);
            hotelPanel.find('.hotel-panel-address').html(hotelInfo.address);
            if (parseInt(hotelInfo.longitude) !== 0 && parseInt(hotelInfo.latitude) !== 0) {
                hotelPanel.find('.hotel-panel-map').removeClass('hidden');
                hotelPanel.find('.hotel-panel-map').attr('href', '/Home/BookPage/map.html?hotel=' + window.currentHotel + '&name=' + encodeURIComponent(hotelInfo.hotelName) + '&address=' + encodeURIComponent(hotelInfo.address) + '&longitude=' + hotelInfo.longtitude + '&latitude=' + hotelInfo.latitude);
            }
            hotelPanel.find('.hotel-panel-telephone').html(hotelInfo.telephone);
            hotelPanel.find('.hotel-panel-wechat').html(hotelInfo.wechat);
            if(hotelInfo.hotline == ''){
                hotelPanel.find('.complaint-hidden').hide();
            }else{
                hotelPanel.find('.complaint-hidden').show();
                hotelPanel.find('.hotel-panel-complaint').html(hotelInfo.hotline);
            }
            
            hotelPanel.find('.hotel-panel-desc').html(hotelInfo.description);
            var hotelPanelSpecial = $('#hotel-panel-special-container');
            hotelPanelSpecial.find('.hotel-panel-special').html(hotelInfo.special);
            hotelPanelSpecial.find('.hotel-panel-special-img').attr('data-original', hotelInfo.specialImageUrl).lazyload();
            
            var specialTagHTML = '';
            var templateTagHTML = $($('#templateTag').clone().html());
            var hotel_tag_container = $('.hotel-panel-tag-container');
            if(hotelInfo.specialTag.length >0){
                hotel_tag_container.closest('.content-panel').removeClass('hidden');
                hotel_tag_container.closest('.content-panel').prev('.content-outside-title').removeClass('hidden');
                $.each(hotelInfo.specialTag, function(key, value) {
                    templateTagHTML.html(value);
                    specialTagHTML += templateTagHTML.prop('outerHTML');
                });
                hotel_tag_container.html(specialTagHTML);                
            }
            var hotelPanelCarousel = $('#hotel-panel-carousel');
            hotelPanelCarousel.find('.inner-item').attr('data-original', hotelInfo.gallery[0]).lazyload();
            var carouselHTML = '';
            var carouselIndicatorHTML = '';
            var templateCarousel = $($('#templateCarouselItem').clone().html());
            var templateCarouselIndicator = $($('#templateCarouselIndicator').clone().html());
            $('#hotel-panel-carousel').on('click','.inner-item',function(){
                var original = $(this).data('original');
                var picArr = [];
                $.each(hotelInfo.gallery, function(key, value) {
                    if(value == original){
                        picArr.unshift(value);
                    }else{
                        picArr.push(value);
                    }
                });
                window.location.href = '/Home/BookPage/indexpic?hotel=' + window.currentHotel+'&pic='+picArr.join(',');
            });            
            
            $.each(hotelInfo.gallery, function(key, value) {
                if (key === 0) {
                    return true;
                }
                templateCarousel.find('.inner-item').attr('data-original', value);
                templateCarouselIndicator.attr('data-slide-to', key);
                carouselHTML += templateCarousel.prop('outerHTML');
                carouselIndicatorHTML += templateCarouselIndicator.prop('outerHTML');
            });
            hotelPanelCarousel.find('.carousel-inner').append(carouselHTML);
            $('.carousel .inner-item').lazyload({
                skip_invisible: true
            });
            hotelPanelCarousel.find('.carousel-indicators').append(carouselIndicatorHTML);
            var facilityHTML = '';
            $('#hotel-panel-facility').attr('data-value',hotelInfo.facility);
            $.each(hotelInfo.facility, function(key, value) {
                templateTagHTML.html("&nbsp;");
                if(value == lang('wirelessNetworks')){
                    templateTagHTML.removeClass().addClass('facility-wireless-networks hotel-panel-tag nowrap-content');
                }
                if(value == lang('park')){
                    templateTagHTML.removeClass().addClass('facility-park hotel-panel-tag nowrap-content');
                }
                if(value == lang('breakfast')){
                    templateTagHTML.removeClass().addClass('facility-breakfast hotel-panel-tag nowrap-content');
                }
                if(value == lang('midding')){
                    templateTagHTML.removeClass().addClass('facility-midding hotel-panel-tag nowrap-content');
                }
                if(value == lang('westernFood')){
                    templateTagHTML.removeClass().addClass('facility-western-food hotel-panel-tag nowrap-content');
                }
                if(value == lang('cafe')){
                    templateTagHTML.removeClass().addClass('facility-cafe hotel-panel-tag nowrap-content');
                }
                if(value == lang('gym')){
                    templateTagHTML.removeClass().addClass('facility-gym hotel-panel-tag nowrap-content');
                }
                if(value == lang('swimming')){
                    templateTagHTML.removeClass().addClass('facility-swimming hotel-panel-tag nowrap-content');
                }
                if(value == lang('bar')){
                    templateTagHTML.removeClass().addClass('facility-bar hotel-panel-tag nowrap-content');
                }
                if(value == lang('chirapsia')){
                    templateTagHTML.removeClass().addClass('facility-chirapsia hotel-panel-tag nowrap-content');
                }
                if(value == lang('hotWater')){
                    templateTagHTML.removeClass().addClass('facility-hot-water hotel-panel-tag nowrap-content');
                }
                facilityHTML += templateTagHTML.prop('outerHTML');
            });
            $('#hotel-panel-facility').html(facilityHTML);
            if(hotelInfo.hourroom){
                if (Object.keys(hotelInfo.hourroom).length > 0) {
                    var hourRoom = hotelInfo.hourroom;
                    var currentHour = $('.room-panel-time').data('hour');
                    $('#hour-room-title').text(lang('booktime') + hourRoom.checkintime + ':00' + '-'+ hourRoom.checkouttime + ':00'); 
                    if (currentHour < hourRoom.checkouttime) {
                        if (currentHour < hourRoom.checkintime) {
                            currentHour = hourRoom.checkintime;
                        }  
                        for (var i = currentHour; i < parseInt(hourRoom.checkouttime); i++) {
                            $("#hour-ul").append("<li class='li-option' data-value='"+i+"'><a href='#'>"+i+"</a></li>");
                        }
                        for (var i = 0; i <= 9; i++) {
                            var D=['00','01','02','03','04','05','06','07','08','09'];
                            $("#minute-ul").append("<li class='li-option' data-value='"+D[i]+"'><a href='#'>"+D[i]+"</a></li>");
                        }
                        for (var i = 10; i <= 59; i++) {
                            $("#minute-ul").append("<li class='li-option' data-value='"+i+"'><a href='#'>"+i+"</a></li>");
                        }
                        $('#select-hour-checkintime').text(currentHour);
                        $('#select-hour-checkintime').data('value', currentHour);
                        $('#select-minute-checkintime').data('value', '00');
                        $('.room-panel-time').text(currentHour+':00');
                        $('#zhongdianfang').removeClass('hidden');
                        $('#choose-room-btn').removeClass('hidden');
                    }
                }
            };
            if(hotelInfo.longroom){
                if (Object.keys(hotelInfo.longroom).length > 0) {
                    $('#changzufang').removeClass('hidden');
                    $('#choose-room-btn').removeClass('hidden');
                }                
            }

        }, function(error) {
            toggleLoading(false);
            toastr.error(typeof error.responseJSON === 'undefined' ? lang('tip.system') : error.responseJSON.info);
        });
        var today = $('#doc').data('start');
        $('#doc-body .tabs-tab[href="#room-panel"]').on('tabSelected.ulite.tabs', function(e) {
            var roomPanel = $('#room-panel');
            if (roomPanel.data('has-init') === undefined) {
                initRoomType(today);
                roomPanel.data('has-init', 1);
            }
        });
    }
    $('#hotel-panel-facility').click(function(){
        $("#facility-desc").modal('show');
        var arrValue = $(this).attr('data-value');
        var $ul = $('#facility-desc ul');
        $ul.find('li').remove();
        var arr = arrValue.split(',');
        var arrClass = [];
        for(var i=0;i<arr.length;i++){
            var $class = $("#hotel-panel-facility").children('.hotel-panel-tag').eq(i).attr('class').split(' ')[0];
            arrClass.push($class);
        }
        for(var i=0;i<arr.length;i++){
            var $li = $('<li/>').text(arr[i]).addClass(arrClass[i]);
            $ul.append($li);
        }
    });
    var hooseRoom =$('#choose-room-btn .text-value');
    $('#jianyefang').click(function(){
        $(this).addClass('button-click').siblings().removeClass('button-click');
        $('.normal-room').removeClass('hidden');
        $('.long-room').addClass('hidden');
        $('.hour-room').addClass('hidden');
        hooseRoom.text($(this).find('a').text());
        $('#room-panel .room-panel-type-img').lazyload({
            'skip_invisible': true
        });
    });

    $('#zhongdianfang').click(function(){
        $(this).addClass('button-click').siblings().removeClass('button-click');
        $('.room-panel-type-img').trigger("click");
        $('.normal-room').addClass('hidden');
        $('.long-room').addClass('hidden');
        $('.hour-room').removeClass('hidden');
        hooseRoom.text($(this).find('a').text());
        $('#room-panel .room-panel-type-img').lazyload({
            'skip_invisible': true
        });
    });

    $('#changzufang').click(function(){
        $(this).addClass('button-click').siblings().removeClass('button-click');
        $('.room-panel-type-img').trigger("click");
        $('.normal-room').addClass('hidden');
        $('.hour-room').addClass('hidden');
        $('.long-room').removeClass('hidden');
        hooseRoom.text($(this).find('a').text());
        $('#room-panel .room-panel-type-img').lazyload({
            'skip_invisible': true
        });
    });

    $(document).on('click', '.li-option',function() {
        var span = $(this).parent().siblings().find('.select-text');
        span.text($(this).text());
        span.data('value', $(this).data('value'));
    });
    var requestRoomTypeDetail = function(hotelId, checkInDate, checkOutDate) {
        toggleLoading(true);
        window.checkInDate = checkInDate;
        window.checkOutDate = checkOutDate;
        ajaxRequest('/Home/Room/roomTypes', {
            'hotel': hotelId,
            'startDate': checkInDate,
            'endDate': checkOutDate,
            'transCurrencyId':window.transCurrencyId
        }, 'post', function(data) {
            var hotelInfo = data.data;
            $('#room-panel .room-panel-date').html(hotelInfo.startDate.substr(5));
            $('#room-panel .room-panel-night').html(hotelInfo.nights);
            // 0表示预定房间
            var isBookingRoom = parseInt(hotelInfo.bookMode) === 0;
            var noBookingRoom = parseInt(hotelInfo.bookMode) === 1;
            var hotelCurrencyHTML = '';
            if(hotelInfo.hotelCurrency.length>0){
                $.each(hotelInfo.hotelCurrency, function(key, type) {
                    var templateCurrencyHTML = $($('#templateCurrency').clone().html());
                    templateCurrencyHTML.find('a').text(type.name).attr({'data-value':type.currencyId,'data-symbols':type.symbol});
                    if(type.symbol==window.symbols){
                        templateCurrencyHTML.addClass('button-click');
                        $('.multiCurrencySelect').find('[data-toggle="dropdown"]').attr('data-value',type.currencyId).find('.info').html(type.name);
                    }
                    hotelCurrencyHTML += templateCurrencyHTML.prop('outerHTML');
                });
                $('.multiCurrencySelect .dropdown-menu').html(hotelCurrencyHTML);
                $('.multiCurrencySelect').removeClass('hidden');                
            }
            var roomTypeHTML = '';
            $.each(hotelInfo.roomTypes, function(key, type) {
                var templateRoomTypeHTML = $($('#templateRoomType').clone().html());
                templateRoomTypeHTML.find('.room-panel-type-img').attr('data-original', type.coverImageUrl);
                templateRoomTypeHTML.find('.room-panel-type-name').html(type.name);
                templateRoomTypeHTML.find('.room-panel-type-shopprice').html(parseFloat(type.shopPrice).toFixed(2));
                templateRoomTypeHTML.find('.text-symbols').html(window.symbols);
                templateRoomTypeHTML.find('.room-panel-type-price').html(parseFloat(type.price).toFixed(2));
                if(parseFloat(type.charityPrice) != 0){
                    templateRoomTypeHTML.find('.charityPrice').removeClass('hidden');
                }
                if (type.shopPrice != '') {
                    templateRoomTypeHTML.find('.text-symbols-shopprice').html(window.symbols);
                    templateRoomTypeHTML.find('.text-hide').removeClass('hidden').find('.room-panel-type-shopprice').html(parseFloat(type.shopPrice).toFixed(2));
                }
                if(type.isOffline == true){
                    templateRoomTypeHTML.find('.line-down-pay').removeClass('hidden');
                    templateRoomTypeHTML.find('.room-panel-type-book').removeClass('addstyle');
                }else{
                    templateRoomTypeHTML.find('.line-down-pay').addClass('hidden');
                    templateRoomTypeHTML.find('.room-panel-type-book').addClass('addstyle');
                }
                var restRoomCount = parseInt(type.rest);
                if (restRoomCount === 0) {
                    templateRoomTypeHTML.find('.room-panel-type-book').addClass('hidden');
                    if(noBookingRoom){
                        templateRoomTypeHTML.find('.room-panel-type-surplus-info').html(lang('fullHouse'));
                    }
                    if(isBookingRoom){
                        templateRoomTypeHTML.find('.room-panel-type-surplus-info').html(lang('fullHouse'));
                    }
                } else {
                    templateRoomTypeHTML.find('.room-panel-type-book').removeClass('hidden').attr('data-value', type.id);
                    if (isBookingRoom) {
                        templateRoomTypeHTML.find('.room-panel-type-surplus-info').html(lang('left')+'<span class="room-panel-type-surplus">'+restRoomCount+'</span>'+lang('rooms'));
                    }  
                    if(noBookingRoom){
                        templateRoomTypeHTML.find('.room-panel-type-surplus-info').html('');
                    }
                }
                if(type.lastRoom == true){
                    type.description = '<div class="book-panel-tag nowrap-content">'+lang('cuxiao')+'</div>'+ type.description;
                }
                templateRoomTypeHTML.find('#text-desc').html(type.description);
                if(type.minustype == 0){
                    templateRoomTypeHTML.find('.room-panel-discounts-info').addClass('hidden');
                }else{
                    templateRoomTypeHTML.find('.room-panel-discounts-info').removeClass('hidden');
                }                
                roomTypeHTML += templateRoomTypeHTML.prop('outerHTML');
            });
            $('#room-panel .room-panel-types').html(roomTypeHTML);
            $('#room-panel .room-panel-type-img').lazyload({
                'skip_invisible': true
            });
            toggleLoading(false);
        }, function(error) {
            toggleLoading(false);
            toastr.error(typeof error.responseJSON === 'undefined' ? lang('tip.system') : error.responseJSON.info);
        });
    };
    var initRoomType = function(today) {
        $('#room-panel .room-panel-date').html(today.substr(5));
        var todayDate = getDate(today);
        var endDate = todayDate.customDays(1).customFormat();
        var dates = 30;
        if(window.isSplitOrderTime){
            endDate = today;
            dates = 29;
        };
        
        $('#dateRangePicker').dateRangePickerMobile({
            dateLimit: dates,
            showWeek: false,
            minDate: today,
            maxDate: todayDate.customDays(365).customFormat(),
            startDate: today,
            endDate: endDate,
            locale: {
                startDateLabel: '',
                endDateLabel: ''
            }
        });
        $('#dateRangePicker').on('end.amos.drpm', function(e) {
            var checkInDate = e.startDate;
            var checkOutDate = e.endDate;
            var interval = getDate(checkOutDate).getDays(getDate(checkInDate));
            $('#room-panel .room-panel-date').html(checkInDate.substr(5));
            $('#room-panel .room-panel-night').html(interval);
            $('#calendarModal').modal('hide');
            requestRoomTypeDetail(window.currentHotel, checkInDate, checkOutDate);
        });       
        $('#room-panel .room-panel-date-picker').on('click', function(e) {
            e.preventDefault();
            e.stopPropagation();
            $('#calendarModal').modal('show');
        });
        $('#room-panel').on('click', '.room-panel-type-book', function(e) {
            e.preventDefault();
            e.stopPropagation();
            var typeId = $(this).data('value');
            window.location.href = '/Home/BookPage/room?hotel=' + window.currentHotel + '&roomType=' + typeId + '&startDate=' + window.checkInDate + '&endDate=' + window.checkOutDate;
        });
        requestRoomTypeDetail(window.currentHotel, today, endDate);

        var requestHourRoomTypeDetail = function(hotelId, checkInDate, checkOutDate, hour) {
            window.checkInDate = checkInDate;
            window.checkOutDate = checkOutDate;
            ajaxRequest('/Home/Room/hourRoomTypes', {
                'hotel': hotelId,
                'startDate': checkInDate,
                'endDate': checkOutDate,
                'hour' : hour,
                'transCurrencyId':window.transCurrencyId
            }, 'post', function(data) {
                var hotelInfo = data.data;
                // 0表示预定房间
                var isBookingRoom = parseInt(hotelInfo.bookMode) === 0;
                var noBookingRoom = parseInt(hotelInfo.bookMode) === 1;
                var roomTypeHTML = '';
                $.each(hotelInfo.roomTypes, function(key, type) {
                    var templateRoomTypeHTML = $($('#templateHourRoomType').clone().html());
                    templateRoomTypeHTML.find('.room-panel-type-img').attr('data-original', type.coverImageUrl);
                    templateRoomTypeHTML.find('.room-panel-type-name').html(type.name);
                    templateRoomTypeHTML.find('.text-symbols').html(window.symbols);
                    templateRoomTypeHTML.find('.room-panel-type-price').html(parseFloat(type.price).toFixed(2));
                    if(parseFloat(type.charityPrice) != 0){
                        templateRoomTypeHTML.find('.charityPrice').removeClass('hidden');
                    }
                    if(type.isOffline == true){
                        templateRoomTypeHTML.find('.line-down-pay').removeClass('hidden');
                        templateRoomTypeHTML.find('.hour-room-book').removeClass('addstyle');
                    }else{
                        templateRoomTypeHTML.find('.line-down-pay').addClass('hidden');
                        templateRoomTypeHTML.find('.hour-room-book').addClass('addstyle');
                    }
                    var restRoomCount = parseInt(type.rest);
                    if (restRoomCount === 0) {
                        templateRoomTypeHTML.find('.hour-room-book').addClass('hidden');
                        if(noBookingRoom){
                            templateRoomTypeHTML.find('.room-panel-type-surplus-info').html(lang('fullHouse'));
                        }
                        if(isBookingRoom){
                            templateRoomTypeHTML.find('.room-panel-type-surplus-info').html(lang('fullHouse'));
                        }
                    } else {
                        templateRoomTypeHTML.find('.hour-room-book').removeClass('hidden').attr('data-value', type.id);
                        if (isBookingRoom) {
                            templateRoomTypeHTML.find('.room-panel-type-surplus-info').html(lang('left')+'<span class="room-panel-type-surplus">'+restRoomCount+'</span>'+lang('rooms'));
                        }  
                        if(noBookingRoom){
                            templateRoomTypeHTML.find('.room-panel-type-surplus-info').html('');
                        }
                    }
                    templateRoomTypeHTML.find('#text-desc').html(type.description);
                    roomTypeHTML += templateRoomTypeHTML.prop('outerHTML');
                });
                $('#room-panel .hour-room-panel-types').html(roomTypeHTML);
                $('#room-panel .room-panel-type-img').lazyload({
                    'event': 'click',
                    'skip_invisible': true
                });
            }, function(error) {
                toastr.error(typeof error.responseJSON === 'undefined' ? lang('tip.system') : error.responseJSON.info);
            });
        };

        $('#room-panel .room-panel-time-picker').on('click', function(e) {
            e.preventDefault();
            e.stopPropagation();
            $('#hourRoomModal').modal('show');
        });

        requestHourRoomTypeDetail(window.currentHotel, today, endDate, $('.room-panel-hour').text());

        $('#submitHour').click(function () {
            var selectHour = $('#select-hour').data('value');
            $('.room-panel-hour').text(selectHour);
            var selectCheckinHour = $('#select-hour-checkintime').data('value');
            var selectCheckinMinute = $('#select-minute-checkintime').data('value');
            $('.room-panel-time').text(selectCheckinHour+':'+selectCheckinMinute);
            requestHourRoomTypeDetail(window.currentHotel, today, endDate, selectHour);
            $('#hourRoomModal').modal('hide');
        });

        $('#room-panel').on('click', '.hour-room-book', function(e) {
            e.preventDefault();
            e.stopPropagation();
            var typeId = $(this).data('value');
            var checkintime = $('.room-panel-time').text();
            var hour = $('.room-panel-hour').text();
            window.location.href = '/Home/BookPage/hourroom?hotel=' + window.currentHotel + '&roomType=' + typeId + '&startTime=' + checkintime + '&hour=' + hour;
        });

        var requestLongRoomTypeDetail = function(hotelId, checkInDate, month) {
            toggleLoading(true);
            ajaxRequest('/Home/Room/longRoomTypes', {
                'hotel': hotelId,
                'startDate': checkInDate,
                'month': month,
                'transCurrencyId':window.transCurrencyId
            }, 'post', function(data) {
                var hotelInfo = data.data;
                // 0表示预定房间
                var isBookingRoom = parseInt(hotelInfo.bookMode) === 0;
                var noBookingRoom = parseInt(hotelInfo.bookMode) === 1;
                var roomTypeHTML = '';
                $.each(hotelInfo.roomTypes, function(key, type) {
                    var templateRoomTypeHTML = $($('#templateLongRoomType').clone().html());
                    templateRoomTypeHTML.find('.room-panel-type-img').attr('data-original', type.coverImageUrl);
                    templateRoomTypeHTML.find('.room-panel-type-name').html(type.name);
                    templateRoomTypeHTML.find('.text-symbols').html(window.symbols);
                    templateRoomTypeHTML.find('.room-panel-type-price').html(parseFloat(type.price).toFixed(2));
                    if(parseFloat(type.charityPrice) != 0){
                        templateRoomTypeHTML.find('.charityPrice').removeClass('hidden');
                    }
                    if(type.isOffline == true){
                        templateRoomTypeHTML.find('.line-down-pay').removeClass('hidden');
                        templateRoomTypeHTML.find('.long-room-book').removeClass('addstyle');
                    }else{
                        templateRoomTypeHTML.find('.line-down-pay').addClass('hidden');
                        templateRoomTypeHTML.find('.long-room-book').addClass('addstyle');
                    }
                    var restRoomCount = parseInt(type.rest);
                    if (restRoomCount === 0) {
                        templateRoomTypeHTML.find('.long-room-book').addClass('hidden');
                        if(noBookingRoom){
                            templateRoomTypeHTML.find('.room-panel-type-surplus-info').html(lang('fullHouse'));
                        }
                        if(isBookingRoom){
                            templateRoomTypeHTML.find('.room-panel-type-surplus-info').html(lang('fullHouse'));
                        }
                    } else {
                        templateRoomTypeHTML.find('.long-room-book').removeClass('hidden').attr('data-value', type.id);
                        if (isBookingRoom) {
                            templateRoomTypeHTML.find('.room-panel-type-surplus-info').html(lang('left')+'<span class="room-panel-type-surplus">'+restRoomCount+'</span>'+lang('rooms'));
                        }
                        if(noBookingRoom){
                            templateRoomTypeHTML.find('.room-panel-type-surplus-info').html('');
                        }
                    }
                    templateRoomTypeHTML.find('#text-desc').html(type.description);
                    roomTypeHTML += templateRoomTypeHTML.prop('outerHTML');
                });
                $('#room-panel .long-room-panel-types').html(roomTypeHTML);
                $('#room-panel .room-panel-type-img').lazyload({
                    'skip_invisible': true
                });
                toggleLoading(false);
            }, function(error) {
                toggleLoading(false);
                toastr.error(typeof error.responseJSON === 'undefined' ? lang('tip.system') : error.responseJSON.info);
            });
        };
        requestLongRoomTypeDetail(window.currentHotel, today, 1);
        $('#room-panel').on('click', '.long-room-book', function(e) {
            e.preventDefault();
            e.stopPropagation();
            var typeId = $(this).data('value');
            var checkinDate =  $('.room-panel-long').text();
            var month =  $('.room-panel-month').text();
            window.location.href = '/Home/BookPage/longroom?hotel=' + window.currentHotel + '&roomType=' + typeId + '&startDate=' + checkinDate + '&month=' + month;
        });

        $('#room-panel .room-panel-long-picker').on('click', function(e) {
            e.preventDefault();
            e.stopPropagation();
            $('#longRoomModal').modal('show');
        });

        $("#datepicker").datepicker({
            format: 'yyyy-mm-dd',
            language: lang('language'),
            autoclose: true,
        });

        $('#submitLong').click(function () {
            var selectLong = $('#select-long').data('value');
            $('.room-panel-month').text(selectLong);
            var selectCheckinDay = $('#datepicker').val();
            $('.room-panel-long').text(selectCheckinDay);
            requestLongRoomTypeDetail(window.currentHotel, selectCheckinDay, selectLong);
            $('#longRoomModal').modal('hide');
        });

    };
    var isWechat = function() {
        var ua = navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == "micromessenger") {
            return true;
        } else {
            return false;
        }
    };

    if (isWechat()) {
        ajaxRequest('/Home/User/info', {}, 'post', function(data) {}, function(error) {
            window.location.href = 'http://cz.uclbrt.com/Wechat/WechatLoginPage/auth.html?type=mz&hotel=' + window.currentHotel;
        });
    }
    var getParams = getArgs();
    var BindName = getParams.name; 
    var tabsTabBar = $('#doc-body .tabs-tab-bar a');
    if(BindName){
        tabsTabBar.eq(0).removeClass('is-active');
        tabsTabBar.eq(1).addClass('is-active');
        $('#hotel-panel').removeClass('is-active');
        $('#room-panel').addClass('is-active');
        $('#doc-body .tabs-tab[href="#room-panel"]').trigger('tabSelected.ulite.tabs');
    }
    //优惠劵
    var islogin = $('#doc').data('islogin');
    var importModal = $('#importModal');
    var robModal = $('#robModal');
    var snagModal = $('#snagModal');
    var loseModal = $('#loseModal');
    var enterCoupon = $('#enter-hotel-coupon');
    enterCoupon.on('click','.enter-coupon-close',function(e){
        e.stopPropagation(); 
        enterCoupon.addClass('hidden');
    });
    var getRobCoupon = function(){
        toggleLoading(true);
        ajaxRequest('/Home/Coupon/addUserCoupon', {
            "hotel": window.currentHotel,
            "couponNo":window.couponNo
        }, 'post', function (data) {
            toggleLoading(false);
            if(window.couponType == 1){
                snagModal.find('.coupon-price').removeClass('hidden').find('span').text(window.couponMinusPrice);
            }else{
                snagModal.find('.coupon-discount').removeClass('hidden').find('span').text(window.couponDiscount);
            }                
            snagModal.removeClass('hidden');
        }, function(error){
            toggleLoading(false);
            loseModal.removeClass('hidden');
        });         
    };
    robModal.on('click','.coupon-close',function(e){
        e.stopPropagation();
        robModal.addClass('hidden');
        $.cookie('coupon_cookie', window.couponNo, { expires: 7, path: '/' })
    }).on('click','.robButton',function(e){
        e.stopPropagation();
        robModal.addClass('hidden');
        if(islogin != 0 && islogin != ''){
            getRobCoupon();
        }else{
            if(window.couponType == 1){
                importModal.find('.coupon-price').removeClass('hidden').find('span').text(window.couponMinusPrice);
            }else{
                importModal.find('.coupon-discount').removeClass('hidden').find('span').text(window.couponDiscount);
            }                
            importModal.removeClass('hidden');    
        }        
    });
    snagModal.on('click','.coupon-close',function(e){
        e.stopPropagation();
        snagModal.addClass('hidden');
        $.cookie('coupon_cookie', window.couponNo, { expires: 7, path: '/' })
    });   
    loseModal.on('click','.coupon-close',function(e){
        e.stopPropagation();
        loseModal.addClass('hidden');
        $.cookie('coupon_cookie', window.couponNo, { expires: 7, path: '/' })
    }).on('click','.coupon-again span',function(e){
        e.stopPropagation();
        loseModal.addClass('hidden');
        getRobCoupon();
    });   
    importModal.on('click','.coupon-close',function(e){
        e.stopPropagation(); 
        importModal.addClass('hidden');
        $.cookie('coupon_cookie', window.couponNo, { expires: 7, path: '/' })
    });
    importModal.on('click','.getCode', function (e) {
        var submitBtn = $(this);
        var params = {};
        params.mobile = importModal.find('.requestMobile').val();
        params.areaCode = importModal.find('.areaCodeValue').text().trim();
        if(params.mobile == ''){
            toastr.error(lang('tip.mobileWrite'))
            return false;
        }
        ajaxRequest('/Home/Public/smsCouponLoginVcode', params, 'post', function (data) {
            timeDisplay(submitBtn, 60);
        }, function (error) {
            toastr.error(typeof error.responseJSON === 'undefined' ? lang('tip.server') : error.responseJSON.info);
        });
    });  
    importModal.on('click','.coupon-receive span',function(e){
        e.stopPropagation(); 
        var params = {};
        var ret = /^\d{4}$/;
        params.hotel = window.currentHotel;
        params.couponNo = window.couponNo;
        params.mobile = importModal.find('.requestMobile').val();
        params.areaCode = importModal.find('.areaCodeValue').text().trim();
        params.vcode = importModal.find('.requestCode').val();
        if(params.mobile == ''){
            toastr.error(lang('tip.mobileWrite'))
            return false;
        }
        if(params.vcode == ''){
            toastr.error(lang('tip.messageNull'))
            return false;
        }
        if(!ret.test(params.vcode)){
            toastr.error(lang('tip.message'))
            return false;
        }
        ajaxRequest('/Home/Public/getCouponAndSmsLogin',params, 'post', function (data) {
            importModal.addClass('hidden');
            if(window.couponType == 1){
                snagModal.find('.coupon-price').removeClass('hidden').find('span').text(window.couponMinusPrice);
            }else{
                snagModal.find('.coupon-discount').removeClass('hidden').find('span').text(window.couponDiscount);
            }                
            snagModal.removeClass('hidden');
        }, function(error){
            toastr.error(typeof error.responseJSON === 'undefined' ? lang('tip.server') : error.responseJSON.info);
        });  
    });     
    //多元货币
    $('.multiCurrencySelect').on('click', '.dropdown-menu li>a', function(e) {
        var item = $(this);
        var liItem = item.parents('li');
        var toggle = liItem.parents('.dropdown-menu').siblings('[data-toggle="dropdown"]');
        liItem.addClass('button-click');
        liItem.siblings().removeClass('button-click');
        var value = item.data('value');
        var name = item.text();
        toggle.data('value', value);
        toggle.find('.info').html(name);     
        window.symbols = item.data('symbols');
        window.transCurrencyId = value;
        initRoomType(today);
    });        
});
